package br.com.moxeon.control.operation.rules;

import java.util.Date;
import java.util.HashMap;

import br.com.moxeon.model.cash.ThrowOperation;
import br.com.moxeon.model.enums.TypeThrowOperation;

public abstract class FinancialRule implements IFinancialRules{

	private HashMap<String,Object> data;
	private ThrowOperation operation;
	private TypeThrowOperation operationType;
	private Boolean operationExecuted;
	
	public void initRuler(HashMap<String,Object> data, TypeThrowOperation operationType)
	{
		operationExecuted = false;
	    setData(data);
		ThrowOperation throwOperation = (ThrowOperation) getData().get("operation");
		if (throwOperation != null)
			this.operation = throwOperation;
		else
			operation = new ThrowOperation();
		this.operationType = operationType;
	}
	
	@Override
	public void executeOperation() {
		operation.setOparationDate(new Date());
		operation.setTipoOperacao(getOperationType());
	}

	public HashMap<String, Object> getData() {
		return data;
	}

	public void setData(HashMap<String, Object> data) {
		this.data = data;
	}
	
	public ThrowOperation getOperationResult()
	{
		if (this.operationExecuted == true)
			return this.operation;
		else
			return null;
	}

	public TypeThrowOperation getOperationType() {
		return operationType;
	}

	public void setOperationType(TypeThrowOperation operationType) {
		this.operationType = operationType;
	}

	protected ThrowOperation getOperation() {
		return operation;
	}

	protected void setOperation(ThrowOperation operation) {
		this.operation = operation;
	}
	
	public void finalizeOperation()
	{
		this.operationExecuted = true;
	}
}
